package com.xidian.zhiancloud.service.riskcontrol.riskidenva;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xidian.zhiancloud.dao.riskcontrol.riskidenva.TRiskObjectEvaluationAuditMapper;
import com.xidian.zhiancloud.model.riskcontrol.TRiskObjectEvaluationAuditList;
import org.apache.ibatis.jdbc.Null;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

import static com.xidian.zhiancloud.util.tools.StringUtil.isNullOrEmpty;

/**
 *  风险评价审核-审核-对象评价审核
 */
@Service
public class TRiskObjectEvaluationAuditService extends ServiceImpl
        <TRiskObjectEvaluationAuditMapper, TRiskObjectEvaluationAuditList>{

    @Autowired
    TRiskObjectEvaluationAuditMapper tRiskObjectEvaluationAuditMapper;

    public List<TRiskObjectEvaluationAuditList> selectByRObjEvaAudit
            (Long companyId,String taskAllocatId){
        return tRiskObjectEvaluationAuditMapper.selectByRObjEvaAudit(companyId,taskAllocatId);
    }

    public List<TRiskObjectEvaluationAuditList> selectByRObjEvaAuditZero
        (Long companyId,String triskidentevalsId){
        return tRiskObjectEvaluationAuditMapper.selectByRObjEvaAuditZero
            (companyId,triskidentevalsId);
    }

    public List<TRiskObjectEvaluationAuditList> selectByRObjEvaAuditAndIdenId
        (Long companyId,String triskidentevalsId) {
        return tRiskObjectEvaluationAuditMapper.selectByRObjEvaAuditAndIdenId
            (companyId,triskidentevalsId);
    }
    
    public int deleteObjEvaAudit(Long companyId,String taskAllocatId){
        return tRiskObjectEvaluationAuditMapper.deleteObjEvaAudit(companyId,taskAllocatId);
    }

    public int insertTRObjectEvaluationAudit(Long companyId,String id,String taskAllocatId,
           String auditproject,String compliance,String inconformity){
        List<TRiskObjectEvaluationAuditList> objEvaAudList = new ArrayList<>();
        String[] auditprojects = auditproject.split(",");
        String[] compliances = compliance.split(",");
        String[] inconformitys = inconformity.split(",");
        for (int i = 0; i < auditprojects.length; i++) {
            TRiskObjectEvaluationAuditList objEvaAudit = new 
                TRiskObjectEvaluationAuditList();
            objEvaAudit.setCompanyId(companyId);
            objEvaAudit.setTriskidentevalsId(Integer.valueOf(id));
            objEvaAudit.setTaskAllocatId(Integer.valueOf(taskAllocatId));
            objEvaAudit.setAuditproject(auditprojects[i]);
            objEvaAudit.setCompliance(compliances[i]);
            objEvaAudit.setInconformity(inconformitys[i]);
            objEvaAudList.add(objEvaAudit);
        }
        return tRiskObjectEvaluationAuditMapper.insertTRObjectEvaluationAudit(objEvaAudList);
    }


}
